<?php

namespace App\Http\Controllers\App;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\GoodsType;
use App\Models\Goods;

class TypeController extends Controller
{
    /**
     * 分类列表
     *
     * @return void
     */
    public function type()
    {
        $data = GoodsType::good_type();
        
        return self::json($data);
    }
    
    /**
     * 展示商品
     *
     * @return void
     */
    public function goods( Request $request )
    {   
        $type_id = $request->input('type_id', '');
       
        $where   = [
             ['goods_type_id', '=', $type_id],
             ['status', '=', 1],
             ['is_sell', '=', 1],
        ];
      
        $data = Goods::where($where)->select('id', 'pic', 'name', 'retail_price')->orderBy('sort')->orderBy('id', 'desc')->paginate(10)->toArray();

        if ( $data['data'] ) {
            $data['goods'] = $data['data'];
            unset($data['data']);
        } else {
            $data['goods'] = [];
            unset($data['data']);
        }
       
        return self::json( $data );
    }
}
